package test;

import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.nio.ByteBuffer;

/**
 * @author Tang
 * @classname NoContextMain
 * @description [  ]
 * @date 2021/8/17 19:46
 */
@Slf4j
public class NoContextMain {

    public static void main(String[] args) throws Exception {
        User user = new User("tang", "123");
        ByteOutputStream byteOutputStream = new ByteOutputStream();
        ObjectOutputStream o1 = new ObjectOutputStream(byteOutputStream);
        o1.writeObject(user);
        System.out.println(byteOutputStream.getBytes().length);

        ByteBuffer allocate = ByteBuffer.allocate(1024);
        allocate.put(user.name.getBytes());
        allocate.put(user.password.getBytes());
        allocate.flip();
        System.out.println(allocate.limit());
    }

    @Data
    @AllArgsConstructor
    static class User implements Serializable {
        private String name;
        private String password;
    }


}